package com.ynet.middleground.user.service.impl;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.bean.CertMixQueryReqPager;
import com.ynet.middleground.user.common.ErrorMessageConstant;
import com.ynet.middleground.user.dto.CertMixInfoDTO;
import com.ynet.middleground.user.model.CertModel;
import com.ynet.middleground.user.service.CertService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @author liulx
 * @description 软证书(esign)、硬证书(cfca)综合服务实现类
 * @date 2020-01-06 16:57
 */
@Api(value = "证书综合服务", tags = {"证书综合服务"})
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Path("cert-mix")
@Service(timeout = 6000, version = "0.0.1")
public class CertServiceImpl implements CertService, GenericService {

    @Autowired
    CertModel certModel;

    /**
     * 软证书（esign）、硬证书（cfca）综合查询
     *
     * @param queryReq
     *            证书混合查询请求对象
     * @return 证书列表
     */
    @POST
    @ApiOperation(value = "软、硬证书综合查询", notes = "软证书（esign）、硬证书（cfca）综合查询")
    @ApiImplicitParam(name = "requestObj", dataType = "CreateEsignPersonReq", paramType = "body", required = true)
    @Override
    public ServiceResult<List<CertMixInfoDTO>> listCert(CertMixQueryReqPager queryReq) {
        ServiceResult<List<CertMixInfoDTO>> result = new ServiceResult<>();
        try {
            result.setResult(certModel.listCert(queryReq));
            result.setPagerInfo(queryReq.getPagerInfo());
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "软、硬证书综合查询服务异常，case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return result;
        }
        return result;
    }

}
